package com.googlecode.maurersmarbles.drawables;

import java.util.Map;
import java.util.TreeMap;

import com.googlecode.maurersmarbles.GameLogic;
import com.googlecode.maurersmarbles.R;
import com.googlecode.maurersmarbles.Util;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;

public class ImageMarbleDrawable extends MarbleDrawable {

	/**
	 * The map that contains the bitmap for each color.
	 */
	private static final Map<Integer, Bitmap> COLOR_TO_BITMAP_MAP = new TreeMap<Integer, Bitmap>();

	/**
	 * Creates a new ImageMarbleDrawable.
	 * @param player the player number
	 * @param boundingBox the bounding box to draw the marble in
	 */
	public ImageMarbleDrawable(int player, Rect boundingBox) {
		super(player, boundingBox);
	}

	/**
	 * Sets the context and loads the bitmap images.
	 * @param context the context
	 */
	public static void setContext(Context context) {

		Resources resources = context.getResources();

		COLOR_TO_BITMAP_MAP.clear();

		COLOR_TO_BITMAP_MAP.put(GameLogic.COLORS[0], BitmapFactory
				.decodeResource(resources, R.drawable.classic_board_marble_0));
		COLOR_TO_BITMAP_MAP.put(GameLogic.COLORS[1], BitmapFactory
				.decodeResource(resources, R.drawable.classic_board_marble_1));
		COLOR_TO_BITMAP_MAP.put(GameLogic.COLORS[2], BitmapFactory
				.decodeResource(resources, R.drawable.classic_board_marble_2));
		COLOR_TO_BITMAP_MAP.put(GameLogic.COLORS[3], BitmapFactory
				.decodeResource(resources, R.drawable.classic_board_marble_3));

	}

	@Override
	public void drawMarble(Canvas canvas, int startX, int startY, int width,
			int height, int color) {
		Util.drawImage(canvas, COLOR_TO_BITMAP_MAP.get(color), startX, startY,
				width, height);
	}

}
